import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne,CreateDateColumn } from 'typeorm';
import { User } from './user.entity';
import { ProductSku } from './product-sku.entity';
import { OrderItem } from './order-item.entity';
export enum OrderStatus {
  PENDING = 'PENDING',
  PAID = 'PAID',
  SHIPPED = 'SHIPPED',
  COMPLETED = 'COMPLETED',
  CANCELLED = 'CANCELLED',
  REFUNDED = 'REFUNDED'
}

export enum PaymentMethod {
  ALIPAY = 'ALIPAY',
  WECHAT = 'WECHAT',
  BALANCE = 'BALANCE'
}

@Entity('order')
export class Order {
  @PrimaryGeneratedColumn()
  id: number;

  // 关联用户（多对一关系）
  // @ManyToOne(() => User,item => item.id)
  @Column({ name: 'user_id' })
  user_id: number;

  // 订单明细项（一对多关系）
  @OneToMany(() => OrderItem, item => item.order)
  items: OrderItem[];

  // 订单总金额（含两位小数）
    @Column({ type: 'decimal', precision: 10, scale: 2 })
  totalAmount: number;

  // 订单状态枚举：待支付/已支付/已发货等
  @Column({ type: 'enum', enum: OrderStatus, default: OrderStatus.PENDING })
  status: OrderStatus;

  // 订单号码
  @Column({ nullable: true,type: 'varchar', length: 50, unique: true })
  orderNo: string;

  // 支付方式枚举：支付宝/微信/余额支付
  @Column({ type: 'enum', enum: PaymentMethod })
  paymentMethod: PaymentMethod;

  // 第三方支付交易ID
  @Column({ nullable: true })
  transactionId: string;

  // 订单创建时间（自动生成）
  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  @CreateDateColumn()
  createdAt: Date;

  // 支付成功时间
  @Column({ type: 'timestamp', nullable: true })
  @CreateDateColumn()
  paidAt: Date;

  // 收件地址信息（JSON格式存储）
  @Column({ type: 'json', nullable: true })
  shippingAddress: Record<string, any>;

  // 物流单号
  @Column({ nullable: true })
  trackingNumber: string;

  // 快递公司名称
  @Column({ nullable: true })
  courierCompany: string;
  shipping: any;
  @Column({ nullable: false })
  remark: string;



}